﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        订单号：<input id="order_sn" col="order_sn" type="text" />
                    </li>
                   
                    <li>
                        收货人姓名：<input id="shipping_user" col="shipping_user" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group-sm hidden-xs" id="toolbar">
            @*<a id="btnAdd" class="btn btn-success" onclick="showSaveForm(true)"><i class="fa fa-plus"></i> 新增</a>*@
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/QixingManage/OrderMaster/GetPageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'order_sn', title: '订单编号' },
                {
                    field: 'order_type', title: '订单类型',  formatter: function (value, row, index) {
                        if (row.order_type == "@OrderTypeStatus.二手车.ParseToInt()") {
                            return "@OrderTypeStatus.二手车";
                        } else if (row.order_type == "@OrderTypeStatus.新车.ParseToInt()") {
                             return "@OrderTypeStatus.新车";
                        } else if (row.order_type == "@OrderTypeStatus.租车.ParseToInt()") {
                             return "@OrderTypeStatus.租车";
                        }
                    }
                },
                { field: 'shipping_user', title: '收货人姓名' },
                //{ field: 'province', title: '省' },
                //{ field: 'city', title: '市' },
                //{ field: 'district', title: '区' },
                //{ field: 'address', title: '地址' },
                { field: '', title: '收货地址',formatter: function (value, row, index) {
                    return row.province + "-" + row.city + "-" + row.district + "-" + row.address;
                   }
                },
                { field: 'payment_method', title: '支付渠道',  formatter: function (value, row, index) {
                        if (row.payment_method == "@PaymentMethodEnum.现金.ParseToInt()") {
                            return "@PaymentMethodEnum.现金";
                        } else if (row.payment_method == "@PaymentMethodEnum.余额.ParseToInt()") {
                             return "@PaymentMethodEnum.余额";
                        } else if (row.payment_method == "@PaymentMethodEnum.微信.ParseToInt()") {
                             return "@PaymentMethodEnum.微信";
                        } else if (row.payment_method == "@PaymentMethodEnum.支付宝.ParseToInt()") {
                             return "@PaymentMethodEnum.支付宝";
                        } else if (row.payment_method == "@PaymentMethodEnum.网银.ParseToInt()") {
                             return "@PaymentMethodEnum.网银";
                        }
                    }
                },
                { field: 'order_money', title: '订单金额' },
                { field: 'payment_money', title: '支付金额' },
                {
                    field: 'create_time', title: '下单时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                {
                    field: 'shipping_time', title: '发货时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                {
                    field: 'pay_time', title: '支付时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                { field: 'receive_time', title: '收货时间' },
                { field: 'order_status', title: '订单状态',  formatter: function (value, row, index) {
                        if (row.order_status == "@OrderStatusEnum.已关闭.ParseToInt()") {
                            return "@OrderStatusEnum.已关闭";
                        } else if (row.order_status == "@OrderStatusEnum.已发货.ParseToInt()") {
                             return "@OrderStatusEnum.已发货";
                        } else if (row.order_status == "@OrderStatusEnum.已完成.ParseToInt()") {
                             return "@OrderStatusEnum.已完成";
                        } else if (row.order_status == "@OrderStatusEnum.待付款.ParseToInt()") {
                             return "@OrderStatusEnum.待付款";
                        } else if (row.order_status == "@OrderStatusEnum.待发货.ParseToInt()") {
                             return "@OrderStatusEnum.待发货";
                        } else if (row.order_status == "@OrderStatusEnum.无效订单.ParseToInt()") {
                             return "@OrderStatusEnum.无效订单";
                        }
                    }
                },
                { field: 'ordernumber', title: '支付订单号' },
                { field: 'product_cnt', title: '购买数量' },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.order_status== "@OrderStatusEnum.待发货.ParseToInt()")
                        {
                            actions.push('<a class="btn btn-info btn-xs" href="#" onclick="ShippingProduct(\'' + row.Id + '\')"><i class="fa fa-truck"></i>订单发货</a>  ');
                        }
                        actions.push(' <a class="btn btn-info btn-xs" href="#" onclick="OrderDetail(\'' + row.Id + '\')"><i class="fa fa-list-ul"></i>订单详情</a>');
                        return actions.join('');
                    }
                }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function ShippingProduct(id)
    {
         ys.openDialog({
            title:'订单发货',
            content: '@Url.Content("~/QixingManage/OrderMaster/ShippingProductForm")' + '?id=' + id,
            width: '1168px',
            height: '750px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveShippingProductForm(index);
            }
        });
    }

    function OrderDetail(id) {
         ys.openDialog({
            title:'订单详情',
            content: '@Url.Content("~/QixingManage/OrderMaster/MasterOrderDetailForm")' + '?id=' + id,
            width: '1100px',
            height: '750px',
            btn: [],
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? '编辑' : '添加',
            content: '@Url.Content("~/QixingManage/OrderMaster/OrderMasterForm")' + '?id=' + id,
            width: '768px',
            height: '850px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteForm() {
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm('确认要删除选中的' + selectedRow.length + '条数据吗？', function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/QixingManage/OrderMaster/DeleteFormJson")' + '?ids=' + ids,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }
</script>
